﻿SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[bht_ASyncMailStock](
	[RequestId] [int] IDENTITY(1,1) NOT NULL,
	[TemplateId] [int] NOT NULL,
	[Object] [nvarchar](max) NOT NULL,
	[Type] [nvarchar](400) NOT NULL,
	[Receiver] [nvarchar](100) NOT NULL,
	[SetTime] [datetime] NOT NULL,
 CONSTRAINT [PK_bht_ASyncMailStock] PRIMARY KEY CLUSTERED 
(
	[RequestId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[bht_ASyncMailStock] ADD  CONSTRAINT [DF_bht_ASyncMailStock_SetTime]  DEFAULT (getdate()) FOR [SetTime]
GO


CREATE PROCEDURE [dbo].[bhp_ASyncMailStockSave]
	@TemplateId		INT,
	@Object			NVARCHAR(MAX),
	@Type			NVARCHAR(400),
	@Receiver		NVARCHAR(100)
AS
BEGIN

	SET NOCOUNT ON;
	
	INSERT INTO bht_ASyncMailStock (TemplateId, [Object], [Type], Receiver)
		VALUES (@TemplateId, @Object, @Type, @Receiver)
		
	SELECT SCOPE_IDENTITY() as RequestId

END
GO


CREATE PROCEDURE [dbo].[bhp_ASyncMailStockTopGet]
AS
BEGIN

	SELECT TOP 1 * FROM bht_ASyncMailStock ORDER BY SetTime

END

GO

CREATE PROCEDURE [dbo].[bhp_ASyncMailStockGet]
	@RequestId	INT
AS
BEGIN

	SELECT TOP 1 * FROM bht_ASyncMailStock WHERE RequestId = @RequestId

END